package com.example.myandroidapp;

import java.io.IOException;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.util.Log;
import android.view.Menu;

public class FourthActivity extends Activity
{
    private static final String TAG = "FourthActivity";
    
    private static final String urlString = "http://199.102.228.10/~deals/java/response.json";
    
    private static final String urlString2 = "http://199.102.228.10/~deals/test/contacts.json";
    
    private ProgressDialog myProgress;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fourth);
        
        new DataLoadingTask().execute();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        getMenuInflater().inflate(R.menu.activity_fourth, menu);
        return true;
    }
    public class DataLoadingTask extends AsyncTask<Void, Void, Void>
    {

        @Override
        protected void onPostExecute(Void result)
        {
            // TODO Auto-generated method stub

            Log.d(TAG, "----------------about to call display");
            display();

        }

        @Override
        protected void onPreExecute()
        {
            // TODO Auto-generated method stub

            myProgress = new ProgressDialog(FourthActivity.this);

            myProgress.setMessage("Please wait..");

            myProgress.setProgressStyle(ProgressDialog.STYLE_SPINNER);

            myProgress.setCancelable(true);

            myProgress.show();

            Log.d(TAG, "----------------about to call pre-");


        }

        @Override
        protected void onProgressUpdate(Void... values)
        {

            super.onProgressUpdate(values);
        }

        @Override
        protected Void doInBackground(Void... arg0)
        {
            try
            {
                read();
            } catch (IOException e)
            {
                e.printStackTrace();
            }
            return null;
        }

    }
    
    public void read() throws IOException
    {
        ObjectsReader objectsReader = new ObjectsReader();
        
        objectsReader.readPersonResponse(urlString2);
    }
    public void display()
    {
        
    }
}
